// 权限管理
import { ajaxService } from '@/utils/request';
import { RoleList } from './type';

const env = import.meta.env;
const baseURL = env.VITE_APP_BASE_URL;

// 获取角色列表
export function getRoleList(params: any) {
  return ajaxService({
    url: '/auth/role/list',
    method: 'get',
    baseURL,
    params
  });
}

// 获取角色列表(分页)
export function getRolePageList(params: any) {
  return ajaxService({
    url: '/auth/role/page',
    method: 'get',
    baseURL,
    params
  });
}

// 数据查重
export function getRoleParameterDuplicationCheck(params: any) {
  return ajaxService({
    url: '/auth/role/parameter/duplication/check',
    method: 'get',
    baseURL,
    params
  });
}

// 新增角色
export function postRoleList(data: RoleList) {
  return ajaxService({
    url: '/auth/role',
    method: 'post',
    baseURL,
    data
  });
}

// 删除角色
export function delRole(data: any) {
  return ajaxService({
    url: '/auth/role',
    method: 'delete',
    baseURL,
    data
  });
}

// 修改角色
export function putRoleList(data: any) {
  return ajaxService({
    url: '/auth/role',
    method: 'put',
    baseURL,
    data
  });
}

/**
 * 角色互斥
 *
 */

// 获取角色互斥列表
export function getRoleExclusiveList(params: any) {
  return ajaxService({
    url: `/auth/role/mutually/exclusive/list/${params.roleId}`,
    method: 'get',
    baseURL
  });
}

// 新增角色互斥关系
export function postRoleExclusive(data: RoleList) {
  return ajaxService({
    url: '/auth/role/mutually/exclusive',
    method: 'post',
    baseURL,
    data
  });
}

// 获取全部角色列表
export function getRoleListAll(params: RoleList) {
  return ajaxService({
    url: '/auth/all/role/list',
    method: 'get',
    baseURL,
    params
  });
}

/**
 * 角色与权限关系管理
 *
 */

// 获取菜单与角色关系列表
export function getRoleRelList(params: RoleList) {
  return ajaxService({
    url: '/auth/menu/role/rel/list',
    method: 'get',
    baseURL,
    params
  });
}
// 修改菜单与角色关系
export function putRoleRel(data: RoleList) {
  return ajaxService({
    url: '/auth/menu/role/rel',
    method: 'put',
    baseURL,
    data
  });
}

/**
 * 对象与角色关系管理
 *
 */

// 获取菜单与角色关系列表
export function getObjRoleRelList(params: RoleList) {
  return ajaxService({
    url: '/auth/obj/role/rel/list',
    method: 'get',
    baseURL,
    params
  });
}
// 新增菜单与角色关系
export function postObjRoleRel(data: RoleList) {
  return ajaxService({
    url: '/auth/obj/role/rel',
    method: 'post',
    baseURL,
    data
  });
}

// 删除对象与角色关系
export function delObjRoleRel(data: RoleList) {
  return ajaxService({
    url: '/auth/obj/role/rel',
    method: 'delete',
    baseURL,
    data
  });
}

/**
 * 代理角色管理
 *
 */

// 获取当前用户的代理角色列表
export function getAuthAgentList(params?: RoleList) {
  return ajaxService({
    url: '/auth/agent/page',
    method: 'get',
    baseURL,
    params
  });
}

// 新增代理角色
export function postAuthAgent(data: RoleList) {
  return ajaxService({
    url: '/auth/agent',
    method: 'post',
    baseURL,
    data
  });
}

// 修改代理角色信息
export function putAuthAgent(data: RoleList) {
  return ajaxService({
    url: '/auth/agent',
    method: 'put',
    baseURL,
    data
  });
}
// 收回代理角色
export function delAuthAgent(params: any) {
  return ajaxService({
    url: `/auth/recovery/agent/${params.roleId}`,
    method: 'delete',
    baseURL
  });
}

// 获取当前用户去重后的权限树
export function getPermissionDeduplicationTree(params?: RoleList) {
  return ajaxService({
    url: '/auth/permission/tree/of/the/current/user/after/deduplication',
    method: 'get',
    baseURL,
    params
  });
}
